<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button id="but1" onclick="genDivs()">产生三个div</button>
    <button id="but2" onclick="delDivs()">删除所有的div</button>
    <div id="div1"></div>
    <br/>
    <form>
        <input type="button" value="点我"/>
    </form>
    <div>
        <a href="https://www.baidu.com" id="baidu">百度</a>
    </div>
    <script>
        var div = document.querySelector("div")
        var offset = 1
        var aLInk = document.getElementById("baidu")
        function genDivs(){
            for (let index = 0; index < 3; index++) {
                var childNode = document.createElement('div')
                childNode.innerHTML = `这是第${offset+index}个对象`
                div.appendChild(childNode)
            }
            offset +=3
            
        }
        function delDivs(){
            console.log(div.childNodes)
            var length = div.children.length
            for (let index = 0; index < length; index++) {
                div.removeChild(div.childNodes[0])
            }
            offset = 1
        }
    </script>
</body>
</html>